package com.adcc.ags.cgw.entity.msg;

import com.adcc.ags.cgw.entity.BaseEntity;
import com.adcc.utility.mq.entity.Message;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.google.common.base.Optional;
import jersey.repackaged.com.google.common.collect.Sets;

import java.util.Set;
import java.util.UUID;

/**
 * 核心网关消息实体
 */
public class CGWMsg extends BaseEntity {

    // ID
    private String id;

    // 类型
    private MsgType type = MsgType.Downlink;

    // 发送方
    private String sender;

    // 接收方
    private String receiver;

    // 消息路由地址
    private Set<String> destination = Sets.newHashSet();

    // 消息正文
    private Message content;

    /**
     * 构造函数
     * @param content
     */
    public CGWMsg(Message content){
        this.content = content;
    }

    /**
     * 构造函数
     * @param content
     * @param type
     */
    public CGWMsg(Message content, MsgType type) {
        this.id = UUID.randomUUID().toString();
        this.content = content;
        this.type = type;
    }

    /**
     * 构造函数
     * @param content
     * @param type
     * @Param sender
     */
    public CGWMsg(Message content, MsgType type,String sender) {
        this.id = UUID.randomUUID().toString();
        this.content = content;
        this.type = type;
        this.sender = sender;
    }

    /**
     * 构造函数
     * @param content
     * @param type
     * @param destination
     */
    public CGWMsg(Message content,MsgType type,Set<String> destination){
        this.id = UUID.randomUUID().toString();
        this.content = content;
        this.type = type;
        this.destination = destination;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public MsgType getType() {
        return type;
    }

    public void setType(MsgType type) {
        this.type = type;
    }

    public String getSender(){
        return sender;
    }

    public void setSender(String sender){
        this.sender = sender;
    }

    public String getReceiver(){
        return receiver;
    }

    public void setReceiver(String receiver){
        this.receiver = receiver;
    }

    public Set<String> getDestination() {
        return destination;
    }

    public void setDestination(Set<String> destination) {
        this.destination = destination;
    }

    public Message getContent() {
        return content;
    }

    public void setContent(Message content) {
        this.content = content;
    }

    @Override
    public Optional<BaseEntity> formatJson(String json) throws Exception {
        return null;
    }

    @Override
    public String toJSON() throws JsonProcessingException {
        return null;
    }
}
